#include <stdio.h>
#include "light.h"
#include "module.h"
#include "queue.h"



FlowObjList_t good;



static unsigned char CURRENT_HEAD = 0;


void reinit()
{
    good.flowobj_list[CURRENT_HEAD].FlowObj_Steps = STEP_INIT;
}

void suspend()
{
    good.flowobj_list[CURRENT_HEAD].FlowObj_Steps = STEP_SUSPEND;
}

void resume()
{
    good.flowobj_list[CURRENT_HEAD].FlowObj_Steps = STEP_RESUME;
}
 
void run_all()
{
    int i;
    
    int total = create_queue();
    printf("total=%d\r\n", total);

    while (1)
    {
        for (i=0; i<total; i ++)
        {
            MODULE *module = (MODULE *)get(i);
            if (module)
            {
                //printf("get queue[%d] is mark\r\n", i);
                if (module->state == STEP_START)
                {
                    module->state = STEP_RUN;
                    module->Operations->light_init();
                }
                else if (module->state == STEP_RUN)
                {
                    module->state = STEP_RUN;
                    module->Operations->light_run(module);
                }
                else if (module->state == STEP_CLOSE)
                {
                    module->state = STEP_WAIT;
                    module->Operations->light_close();
                }
            }
            else
            {
                //printf("%d=null\r\n", i);
            }
         }
    }
}